#include "opencv2/core/core.hpp"
#include "iostream"

using namespace std;
using namespace cv;


bool matIsEqual(const cv::Mat mat1, const cv::Mat mat2) {
    if (mat1.empty() && mat2.empty()) {
        return true;
    }
    if (mat1.cols != mat2.cols || mat1.rows != mat2.rows || mat1.dims != mat2.dims||
        mat1.channels()!=mat2.channels()) {
        return false;
    }
    if (mat1.size() != mat2.size() || mat1.channels() != mat2.channels() || mat1.type() != mat2.type()) {
        return false;
    }
    int nrOfElements1 = mat1.total()*mat1.elemSize();
    if (nrOfElements1 != mat2.total()*mat2.elemSize()) return false;
    bool lvRet = memcmp(mat1.data, mat2.data, nrOfElements1) == 0;
    return lvRet;
}


cv::Mat getcvMatrixDotProd(cv::Mat A, cv::Mat B )
{
    B = B.t();
    Mat dst_mat( A.rows,B.rows,CV_32FC1);
    for(int i=0;i< A.rows;i++)
    {
        for(int j=0;j<B.rows;j++)
        {
            dst_mat.at<float>(i,j) = A.rowRange(i, i+1).dot(B.rowRange(j, j+1));
            cout << "dot at :"<< i <<","<<j<<":" <<  dst_mat.at<float>(i,j) <<endl;
        }
    }
//    cout << "dst mat :" << dst_mat <<endl;
    return dst_mat ;
}

int main(int argc,char *argv[])
{
    int h_A = 2 , w_A = 3 ;
    Mat A=Mat::ones(h_A,w_A,CV_32FC1);
    int h_B = 3 , w_B = 2 ;
    Mat B=Mat::ones(h_B,w_B,CV_32FC1);
    Mat AB;

    A.at<float>(0,0)=1;
    A.at<float>(0,1)=2;
    A.at<float>(0,2)=3;
    A.at<float>(1,0)=4;
    A.at<float>(1,1)=5;
    A.at<float>(1,2)=6;

    B.at<float>(0,0)=1;
    B.at<float>(0,1)=2;
    B.at<float>(1,0)=3;
    B.at<float>(1,1)=4;
    B.at<float>(2,0)=5;
    B.at<float>(2,1)=6;

    AB=A*B;

    cout<<"A=\n"<<A<<endl<<endl;
    cout<<"B=\n"<<B<<endl<<endl;
    cout<<"AB=\n"<<AB<<endl<<endl;

    cv::Mat dst = getcvMatrixDotProd(A,B);

    cout<<"dst=\n"<<dst<<endl<<endl;

    cout << "mat equal:" << matIsEqual(dst,AB)<<endl;
}



